/*     */ package com.equipmentmanage.dao.impl;
/*     */ 
/*     */ import com.equipmentmanage.dao.EquipmentDao;
import com.equipmentmanage.model.Equipment;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.util.StringUtil;

/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.annotation.Resource;
/*     */ import org.springframework.jdbc.core.JdbcTemplate;
/*     */ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
/*     */ 
/*     */ @Repository("equipmentDao")
/*     */ public class EquipmentDaoImpl
/*     */   implements EquipmentDao
/*     */ {
/*     */ 
/*     */   @Resource
/*     */   private JdbcTemplate jdbcTemplate;
/*     */ 
/*     */   public void add(Equipment equipment)
/*     */   {
/*  31 */     String sql = "insert into t_equipment values(null,?,?,?,?,?)";
/*  32 */     this.jdbcTemplate.update(sql, new Object[] { equipment.getName(), equipment.getNo(), Integer.valueOf(equipment.getTypeId()), Integer.valueOf(equipment.getState()), equipment.getRemark() });
/*     */   }
/*     */ 
/*     */   public void update(Equipment equipment) {
/*  36 */     String sql = "update t_equipment set name=?,no=? ,typeId=?,state=?,remark=? where id=? ";
/*  37 */     this.jdbcTemplate.update(sql, new Object[] { equipment.getName(), equipment.getNo(), Integer.valueOf(equipment.getTypeId()), Integer.valueOf(equipment.getState()), equipment.getRemark(), equipment.getId() });
/*     */   }
/*     */ 
/*     */   public void delete(int id) {
/*  41 */     String sql = "delete from t_equipment where id=?";
/*  42 */     this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(id) });
/*     */   }
/*     */ 
/*     */   public List<Equipment> find(PageBean pageBean, Equipment s_equipment)
/*     */   {
/*  47 */     StringBuffer sb = new StringBuffer("select * from t_equipment t1,t_equipmentType t2 where t1.typeId=t2.id ");
/*  48 */     if ((s_equipment != null) && 
/*  49 */       (StringUtil.isNotEmpty(s_equipment.getName()))) {
/*  50 */       sb.append(" and t1.name like '%" + s_equipment.getName() + "%'");
/*     */     }
/*     */ 
/*  53 */     if (pageBean != null) {
/*  54 */       sb.append(" limit " + pageBean.getStart() + "," + pageBean.getPageSize());
/*     */     }
/*  56 */     final List equipmentList = new ArrayList();
/*  57 */     this.jdbcTemplate.query(sb.toString(), new Object[0], new RowCallbackHandler()
/*     */     {
/*     */       public void processRow(ResultSet rs) throws SQLException
/*     */       {
/*  61 */         Equipment equipment = new Equipment();
/*  62 */         equipment.setId(Integer.valueOf(rs.getInt("id")));
/*  63 */         equipment.setName(rs.getString("name"));
/*  64 */         equipment.setNo(rs.getString("no"));
/*  65 */         equipment.setTypeId(rs.getInt("typeId"));
/*  66 */         equipment.setTypeName(rs.getString("typeName"));
/*  67 */         equipment.setState(rs.getInt("state"));
/*  68 */         equipment.setRemark(rs.getString("remark"));
/*  69 */         equipmentList.add(equipment);
/*     */       }
/*     */     });
/*  72 */     return equipmentList;
/*     */   }
/*     */ 
/*     */   public int count(Equipment s_equipment) {
/*  76 */     StringBuffer sb = new StringBuffer("select count(*) from t_equipment t1,t_equipmentType t2 where t1.typeId=t2.id");
/*  77 */     if ((s_equipment != null) && 
/*  78 */       (StringUtil.isNotEmpty(s_equipment.getName()))) {
/*  79 */       sb.append(" and t1.name like '%" + s_equipment.getName() + "%'");
/*     */     }
/*     */ 
/*  82 */     return ((Integer)this.jdbcTemplate.queryForObject(sb.toString(), Integer.class)).intValue();
/*     */   }
/*     */ 
/*     */   public Equipment loadById(int id) {
/*  86 */     String sql = "select * from t_equipment t1,t_equipmentType t2 where t1.typeId=t2.id and t1.id=? ";
/*  87 */     final Equipment equipment = new Equipment();
/*  88 */     this.jdbcTemplate.query(sql, new Object[] { Integer.valueOf(id) }, new RowCallbackHandler()
/*     */     {
/*     */       public void processRow(ResultSet rs) throws SQLException
/*     */       {
/*  92 */         equipment.setId(Integer.valueOf(rs.getInt("id")));
/*  93 */         equipment.setName(rs.getString("name"));
/*  94 */         equipment.setNo(rs.getString("no"));
/*  95 */         equipment.setTypeId(rs.getInt("typeId"));
/*  96 */         equipment.setTypeName(rs.getString("typeName"));
/*  97 */         equipment.setState(rs.getInt("state"));
/*  98 */         equipment.setRemark(rs.getString("remark"));
/*     */       }
/*     */     });
/* 101 */     return equipment;
/*     */   }
/*     */ 
/*     */   public boolean existEquipmentByTypeId(int typeId) {
/* 105 */     StringBuffer sb = new StringBuffer("select count(*) from t_equipment where typeId=?");
/* 106 */     int result = ((Integer)this.jdbcTemplate.queryForObject(sb.toString(), new Object[] { Integer.valueOf(typeId) }, Integer.class)).intValue();
/* 107 */     if (result > 0) {
/* 108 */       return true;
/*     */     }
/* 110 */     return false;
/*     */   }
/*     */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.dao.impl.EquipmentDaoImpl
 * JD-Core Version:    0.6.1
 */